<?php
/**
 * Created by PhpStorm.
 * User: clb
 * Date: 2019/1/21
 * Time: 15:18
 */

namespace app\server\web\controller;

use app\request\Request;
use app\response\Response;
use app\server\model\{
    Db, Upload, UploadBigFile, UploadSimple
};

class File
{

    /**
     * 上传文件
     */
    public static function upload()
    {
        $request = Request::instance();
        // $db = Db::getInstance()->db;
        // $app = $db->select()->from('bt_app')->where('id= :id')->bindValues(['id' => $request->getQuery('id')])->row();
        $type = $request->getQuery('type');
        $upload = new Upload();
        if (empty($type)) {
            $upload->setStrategy(new UploadSimple());
            $upload->checkSize();
        } else {
            $upload->setStrategy(new UploadBigFile());
        }
        $upload->isEmpty();

        if ( ! empty($upload->errorMsg)) {
            echo Response::instance()->error($upload->errorMsg);
            return;
        }

        $result = $upload->run();

        echo Response::instance()->success('success', $result);
        return;
    }
}






